from django import template

from recommendation.models import Category

register = template.Library()


@register.simple_tag
def get_category_tag(num=8):
    return Category.objects.all()[:num]


@register.simple_tag
def get_category_awesome(category):
    c_dict = {'前端': 'html5', 'IOS': 'apple', '安卓': 'android', '后台': 'server', '产品': 'bolt',
              '设计': 'paint-brush', '运营': 'cogs'}
    if category in c_dict:
        value = c_dict[category]
        return value
    else:
        return " "


def key(d, key_name):
    return d[key_name]


key = register.filter('key', key)
